package com.hzy.fivepalace.admin.config.pay;

import com.hzy.fivepalace.admin.service.AliPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 支付参数配置
 */
@Configuration
public class PayConfig {

    @Autowired
    private AliPayProperties aliPayProperties;

    /**
     * 支付宝支付参数
     *
     * @return
     */
    @Bean
    public AliPayProperties aliPayConfig() {
        AliPayProperties payConfig = new AliPayProperties();
        payConfig.setAppId(aliPayProperties.getAppId());
        payConfig.setPublicKey(aliPayProperties.getPublicKey());
        payConfig.setPrivateKey(aliPayProperties.getPrivateKey());
        payConfig.setNotifyUrl(aliPayProperties.getNotifyUrl());
        payConfig.setPublicKeyPath(aliPayProperties.getPublicKeyPath());
        payConfig.setPublicKeyRsa2Path(aliPayProperties.getPublicKeyRsa2Path());
        payConfig.setRootCertPath(aliPayProperties.getRootCertPath());
        return payConfig;
    }

    /**
     * 支付宝注入
     *
     * @param aliPayProperties
     * @return
     */
    @Bean
    public AliPayService aliPayService(AliPayProperties aliPayProperties) {
        AliPayService aliPayService = new AliPayService();
        aliPayService.setConfig(aliPayProperties);
        return aliPayService;
    }

}
